/**
 * @author Chew Xunmao
 *
 */

package sg.edu.nus.iss.vmcs.iterator;

import sg.edu.nus.iss.vmcs.store.StoreItem;

public class CashCoinDenoIterator implements Iterator {

	private int m_CurrenItemIndex;
	private StoreItem items[];
	private boolean m_StartFromLargestDeno = false;

	public CashCoinDenoIterator(StoreItem pItems[],
			boolean pStartFromLargestDeno) {
		this.items = pItems;
		m_CurrenItemIndex = 0;
		this.m_StartFromLargestDeno = pStartFromLargestDeno;
		if (m_StartFromLargestDeno)
			m_CurrenItemIndex = items.length - 1;
		else
			m_CurrenItemIndex = 0;

	}

	public StoreItem first() {
		// TODO Auto-generated method stub
		return (!m_StartFromLargestDeno) ? items[items.length - 1] : items[0];
	}

	public StoreItem next() {
		// TODO Auto-generated method stub
		StoreItem lResultItem = null;
		lResultItem = items[m_CurrenItemIndex];
		incrementCurrentIndex();
		return lResultItem;


		//return (!m_StartFromLargestDeno) ? items[items.length - 1] : items[0];
	}

	public boolean isDone() {
		// TODO Auto-generated method stub
		if (!m_StartFromLargestDeno)
			return (m_CurrenItemIndex > items.length - 1) ? true : false;
		else
			return (m_CurrenItemIndex < 0) ? true : false;
	}

	public StoreItem currentItem() {
		// TODO Auto-generated method stub
		return items[m_CurrenItemIndex];
	}

	public int getCurrentIndex() {
		return m_CurrenItemIndex;

	}

	private void incrementCurrentIndex() {
		if (!m_StartFromLargestDeno)
			m_CurrenItemIndex += 1;
		else
			m_CurrenItemIndex -= 1;

	}

}
